package com.manager.core.module.manager.controller;

import com.manager.commons.annotation.Module;
import com.manager.commons.base.DataGrid;
import com.manager.core.module.manager.service.PlatformAttributesService;
import com.manager.core.module.manager.entity.PlatformAttributes;
import com.manager.gen.web.controller.AdminController;
import com.manager.core.web.json.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 控制器
 *
 * @author H
 * @version 1.0
 */
@Controller
@Module(parent = "basic-manager", title = "属性配置", show = false,code = "/platform/attributes")
public class PlatformAttributesController extends AdminController<PlatformAttributes> {
    private final String baseUrl = "/platform/attributes";
    @Autowired
    private PlatformAttributesService _service;

    /**
     * 列表
     *
     * @return
     */
    @RequestMapping(baseUrl +"/index")
    public ModelAndView index() {
        return getModelAndView(baseUrl+"/attributes-index");
    }

    /**
     * 列表
     *
     * @return
     */
    @RequestMapping(baseUrl +"/add")
    public ModelAndView add() {
        return getModelAndView(baseUrl + "/attributes-edit", getModel());
    }

    /**
     * 新增
     *
     * @return
     */
    @RequestMapping(baseUrl +"/edit")
    public ModelAndView edit() {
        return getModelAndView(baseUrl + "/attributes-edit", _service.findById(getIdParam()));
    }

    /**
     * 分页
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/list", method = RequestMethod.POST)
    public @ResponseBody DataGrid list() {
        return _service.queryPage(getParams());
    }

    /**
     * 保存数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/save", method = RequestMethod.POST)
    public @ResponseBody AjaxJson save() {
        return _service.save(getParams());
    }

    /**
     * 改变数据状态
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/status", method = RequestMethod.POST)
    public @ResponseBody AjaxJson status() {
        return _service.status(getParams());
    }

    /**
     * 删除数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/delete", method = RequestMethod.POST)
    public @ResponseBody AjaxJson delete() {
        return _service.delete(getParams());
    }

    /**
     * 销毁数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/destroy", method = RequestMethod.POST)
    public @ResponseBody AjaxJson destroy() {
        return _service.destroy(getParams());
    }

    /**
     * 下拉框JSON格式数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl +"/select", method = RequestMethod.POST)
    public @ResponseBody String select() {
        return _service.querySelect(getParams());
    }

    @Override
    public PlatformAttributes getModel() {
        return new PlatformAttributes();
    }
}